<extend name="./public/frame.html"/>
<block name="content">
    <div class="layui-row">
        <div class="layui-col-xs7">
            操作时间-起：
            <div class="layui-inline">
                <input type="text" class="layui-input date" readonly id="start">
            </div>
            操作时间-止：
            <div class="layui-inline">
                <input type="text" class="layui-input date" readonly id="end">
            </div>
        </div>
        <div class="layui-col-xs1">
            <input type="text" lay-verify="required|title" required placeholder="请输入姓名"  class="layui-input" id="name">
        </div>
        <div class="layui-col-xs2">
            <div class="layui-btn-group">
                <button class="layui-btn" data-type="search">搜索</button>
                <button class="layui-btn layui-btn-disabled" data-type="" id="reset">复位</button>
            </div>
        </div>
    </div>
    <table class="layui-table" lay-data="{cellMinWidth: 80, height:'auto', url:'{$url}', page: true,limit: 20, id:'log'}"
           lay-filter="log">
        <thead>
        <tr>
            <th lay-data="{checkbox:true,fixed: true}"></th>
            <th lay-data="{field:'log_id', width:80, fixed: true, sort: true}">ID</th>
            <th lay-data="{field:'admin_name', width:100,}">姓名</th>
            <th lay-data="{field:'content', width:200}">操作内容</th>
            <th lay-data="{field:'add_time', width:170, sort: true,}">操作时间</th>
            <th lay-data="{field:'IP', width:160}">IP</th>
            <th lay-data="{field:'controls', width:160}">控制器</th>
            <th lay-data="{field:'param', width:160}">参数</th>
        </tr>
        </thead>
    </table>

    <script type="application/javascript">
        layui.use(['table','laytpl','laydate'], function () {
            var table = layui.table
                ,laydate = layui.laydate;
            laydate.render({
                elem:'#start'
            });
            laydate.render({
                elem:'#end'
            });
            //监听表格复选框选择
            table.on('checkbox(log)', function (obj) {
                console.log(obj)
            });

            var $ = layui.jquery, active = {
                search: function () {
                    var start = $('#start').val();
                    var end = $('#end').val();
                    var name = $.trim($('#name').val());
                    var reset = $('#reset');
                    if(start||end||name){
                        reset.removeClass('layui-btn-disabled').addClass('layui-btn-normal').data('type', 'reset');
                        table.reload('log', {
                            url: '/admin/admin_log/search',
                            where: {
                                start : start,
                                end : end,
                                name : name
                            } //设定异步数据接口的额外参数
                        });
                    }else{
                        reset.removeClass('layui-btn-normal').addClass('layui-btn-disabled').data('type', '');
                        alert('搜索项不能为空');
                    }
                }
                , reset: function () {
                    var reset = $('#reset');
                    if (reset.data('type') !== '') {
                        table.reload('log', {
                            url: '{$url}',where:{}
                        });
                    }
                    $('.layui-input').each(function () {                        $(this).val('');                    });                $('.layui-this').each(function () {$(this).removeClass('layui-this');});
                    reset.removeClass('layui-btn-normal').addClass('layui-btn-disabled').data('type', '');
                }
            };

            $('.layui-btn').on('click', function () {
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });
        });

    </script>
</block>
